package com.walker.component.page.resolve.query;

import org.apache.commons.lang.StringUtils;

/**
 * 字符串查询器
 * 
 * @author 三丰
 * 
 */
public class StringQueryer extends GeneralQueryer<String> {
	private boolean trim = true;
	private String defaultValue = "";//默认值
	private String addBeforeValue = "";//附加前缀值
	private String addAfterValue = "";//附加后缀值

	public void setTrim(boolean trim) {
		this.trim = trim;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
	public void setAddBeforeValue(String addBeforeValue) {
		this.addBeforeValue = addBeforeValue;
	}
	public void setAddAfterValue(String addAfterValue) {
		this.addAfterValue = addAfterValue;
	}
	public StringQueryer() {
	}

	public StringQueryer(String cssExpression) throws IllegalArgumentException {
		setCssQuery(cssExpression);
	}

	@Override
	public String convert(Object obj) {
		String result = (String) obj;
		if (this.trim) {
			result = result.trim();
		}
		if ((StringUtils.isEmpty(result)) && (!(StringUtils.isEmpty(this.defaultValue)))) {
			result = this.defaultValue;
		}
		result=addBeforeValue+result+addAfterValue;
		return result;
	}
}
